namespace Moe.ECamel.Common.Entities
{
	using System;
	using System.Data;

	public partial class ECamelDataContext
	{
		private bool _closed;
		private readonly Object _closeLock = new object();

		public void Close()
		{
			if (_closed)
				return;

			lock (_closeLock)
			{
				if (_closed)
					return;

				if (this.Connection.State != ConnectionState.Closed)
					this.Connection.Close();

				this.Dispose();
				_closed = true;					
			}
		}
	}	
}
